<?php
namespace app\api\controller\xcx;

use app\BaseController;
use app\common\utils\Curl;
use app\common\utils\Res;
use Exception;
use think\facade\Db;

class Statistics extends BaseController
{
    //统计
    public function getStatistics()
    {
        $param = $this->request->post();

        //获取登录用户ID
        $uid = 1;//$this->request->id;
        
        $map = [];
        $map['type'] = $param['type'] ?? 1;
        $map['date'] = $param['date'] ?? date('Y-m-d', strtotime('-1 day'));
        //获取总数据
        $total_num = Db::table('eat_info')->where('uid',$uid)->count(); // 总单数
        $total_money = Db::table('eat_info')->where('uid',$uid)->sum('price'); // 总价钱
        $total_type_num = Db::table('eat_info')->where('uid',$uid)->where($map)->count(); // 类型的总单数
        $total_type_money = Db::table('eat_info')->where('uid',$uid)->where($map)->sum('price'); // 类型的总价钱
        
        //具体的数据
        $info = Db::table('eat_info')->where($map)->field('id,thing,price,remark')->select();
        
        $data = [
            'total_num' => $total_num,
            'total_money' => $total_money,
            'total_type_num' => $total_type_num,
            'total_type_money' => $total_type_money,
            'info' => $info,
        ];

        return Res::ok($data);
    }
}
